<template>
  <div class="app-container">
    <el-card class="content-edit">
      <div slot="header">
        <span>关于我们</span>
        <el-button type="primary" size="small" style="float: right;" @click="onSubmit">保存</el-button>
      </div>
      <el-form ref="form" :model="form" label-width="120px">
        <el-form-item label="图文详情">
          <ws-editor v-model="form['aboutUs']"/>
        </el-form-item>
        <!--<el-form-item>
          <el-button :loading="loading" type="primary" @click="onSubmit">保存</el-button>
          <el-button @click="$router.back()">取消</el-button>
        </el-form-item>-->
      </el-form>
    </el-card>
  </div>
</template>

<script>
  import WsEditor from 'vue-element-simple/components/UEditor/index';
  export default {
    name: 'InstructionsSublistEdit',
    components: {WsEditor},
    data() {
      return {
        form: {
          // 内容
          aboutUs: ''
        }
      }
    },
    mounted(){
      this.form['id'] = this.$router.currentRoute.query['id'] || '';
      this.loadData();
    },
    methods: {
      // 加载用户信息
      loadData(){
        (async () => {
          const result = await this.$service.applicationGetAboutUsConfig();
          if (result.code === 0) {
            Object.assign(this.form, result.data || {})
          }
        })();
      },
      // 提交
      onSubmit() {
        this.$refs.form.validate(valid => {
          if (valid) {
            (async () => {
              const params = Object.assign({}, this.form);
              const result = await this.$service.applicationSaveAboutUsConfig(params);
              if (result.code === 0) {
                this.$message.success('操作成功~');
                this.loadData();
              } else {
                this.$message.error(result.msg);
              }
            })();
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      }
    }
  }
</script>
